package file;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class FileInputStreamDemo1 {
    public static void main(String[] args) {
        //创建一个字节流
//        InputStream inputStream = null;
//        try {
//            inputStream = new FileInputStream("D:/temp/hello.txt");
//            while (true){
//                int b = inputStream.read();
//                if (b == -1){
//                    break;
//                }
//                System.out.println((char)b);
//            }
//
//
//        }catch (IOException e) {
//            e.printStackTrace();
//        }finally {
//            try {
//                inputStream.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }

        try (InputStream inputStream = new FileInputStream("D:/temp/hello.txt")) {
            while (true) {
                int b = inputStream.read();
                if (b == -1) {
                    break;
                }
                System.out.println((char) b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
